package com.jjsc.cart.api.factory;

import com.jjsc.cart.api.RemoteCartService;
import com.jjsc.cart.api.domain.CartInfo;
import com.jjsc.common.core.domain.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;

import java.util.List;

/**
 * @Author: 钟城明
 * @CreateTime: 2025-10-30
 * @Description:
 * @Version: 1.0
 */
@Slf4j
public class RemoteCartFallbackFactory implements FallbackFactory<RemoteCartService> {

    @Override
    public RemoteCartService create(Throwable cause) {
        return new RemoteCartService() {
            @Override
            public R<List<CartInfo>> getCartCheckedList(Long userId, String source) {
                return R.fail("购物车服务调用失败：" + cause.getMessage());
            }

            @Override
            public R<Boolean> updateCartPrice(Long userId, String source) {
                return R.fail("更新购物车价格失败：" + cause.getMessage());
            }

            @Override
            public R<Boolean> deleteCartCheckedList(Long userId, String source) {
                return R.fail("删除选中的购物车失败：" + cause.getMessage());
            }
        };
    }
}
